using System;
using System.Collections.Generic;
using Microsoft.Scripting.Hosting;
using Triton.Common;

namespace Triton.Bot.Profiles
{
	public static class ProfileScripting
	{
		internal static ScriptManager scriptManager_0;

		public static void Initialize(IEnumerable<Type> shortcutsDefinitions, IEnumerable<string> customNamespaces)
		{
			Deinitialize();
			scriptManager_0 = new ScriptManager();
			scriptManager_0.Initialize(shortcutsDefinitions, customNamespaces);
		}

		public static void Deinitialize()
		{
			if (scriptManager_0 != null)
			{
				scriptManager_0.Deinitialize();
				scriptManager_0 = null;
			}
		}

		public static Func<bool> GetCondition(string expression)
		{
			string expression2 = $"\r\nimport sys\r\nsys.stdout=ioproxy\r\n\r\ndef Execute():\r\n    return bool({expression})";
			ScriptScope scope = scriptManager_0.Scope;
			ScriptSource scriptSource = scriptManager_0.Engine.CreateScriptSourceFromString(expression2);
			scope.SetVariable("ioproxy", scriptManager_0.IoProxy);
			scriptSource.Execute(scope);
			return scope.GetVariable<Func<bool>>("Execute");
		}

		public static Func<T> GetCondition<T>(string expression)
		{
			string expression2 = $"\r\nimport sys\r\nsys.stdout=ioproxy\r\n\r\ndef Execute():\r\n    return bool({expression})";
			ScriptScope scope = scriptManager_0.Scope;
			ScriptSource scriptSource = scriptManager_0.Engine.CreateScriptSourceFromString(expression2);
			scope.SetVariable("ioproxy", scriptManager_0.IoProxy);
			scriptSource.Execute(scope);
			return scope.GetVariable<Func<T>>("Execute");
		}

		public static Action GetPythonStatement(string statement)
		{
			return scriptManager_0.GetStatement(statement);
		}
	}
}
